package com.yunzheng.studyLeaveSystem.modules.enrollAndLogin.enroll.service;

import com.yunzheng.studyLeaveSystem.modules.enrollAndLogin.enroll.dao.MemberDao;
import com.yunzheng.studyLeaveSystem.modules.enrollAndLogin.enroll.dao.MemberDaoImpl;
import com.yunzheng.studyLeaveSystem.modules.enrollAndLogin.login.dao.UserDao;
import com.yunzheng.studyLeaveSystem.modules.enrollAndLogin.login.dao.UserDaoImpl;
import com.yunzheng.studyLeaveSystem.modules.enrollAndLogin.login.entity.Admin;
import com.yunzheng.studyLeaveSystem.modules.enrollAndLogin.login.service.UserService;
import com.yunzheng.studyLeaveSystem.modules.enrollAndLogin.login.service.UserServiceImpl;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: YunZheng
 * @Date: 2023/01/30/10:53
 * @Description:用于注册判断的各种方法
 */
public class MemberServiceImpl implements MemberService{

    UserService userService = new UserServiceImpl();
    UserDao userDao = new UserDaoImpl();
    MemberDao memberDao = new MemberDaoImpl();
    Admin admin = new Admin();
    @Override
    public boolean isCode(String invite_code) {
        String rightCode = admin.getInvite_code();
        if (rightCode.equals(invite_code)){
            return true;
        }
        return false;
    }

    @Override
    public boolean isExistMember(String name, String term, String direction) throws Exception {
        String inTerm = memberDao.queryTerm(name);
        String inDirect = memberDao.queryDirect(name);
        Integer id = memberDao.queryId(name);
        if (id!=0){
            if (term.equals(inTerm)){
                if (direction.equals(inDirect)){
                    return true;
                }
            }
        }
        return false;
    }

    @Override
    public boolean isEnroll(String username, String term, String direction,String gender, String phone_num, String password) throws Exception {
        if (userService.isExist(phone_num)){
            return false;
        }
        return userDao.insert(phone_num,password,username,term,direction,gender);
    }




   
}
